package com.txooo.library.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by 刘志博 on 2017/7/18.
 */

public class CalendarUtils {

    /**
     * 获取过去第几天的日期
     * @param past
     * @return
     */
    public static String getPastDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        String result = format.format(today);
        return result;
    }

    public static String getTime(Date time){
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy.MM.dd");
        String str =formatter.format(time);
        return str;
    }
}
